$(function () {
    $('#deviceCode').focus();
    //重置表单
    $("#searchReset").on("click",function(){
        $('#deviceCode').val('');
        $('#deviceName').val('');
        $('#deviceTable').bootstrapTable('refresh');
    });
    //渲染表格
    var columns = taskList.columnsInit();
    var table = taskList.gridInit(columns);
    var datas = taskList.dataInit();
    $("#deviceTable").bootstrapTable("append",datas);
    //点击删除按钮信息弹出框
    $("#del-btn").click(function(){
        var len = $("#deviceTable input:checked").length;
        if (len == 0) {
            //未选中数据提示框
            layer.msg('请选择数据',  {time:1000});
        } else {
            layer.confirm('确定要删除这条数据吗？',
                {icon: 3, title: '提示', area: '300px', btnAlign: 'c'}, function (index) {
                    layer.close(index);
                });
        }

    });
})
;(function(undefined) {
    "use strict"
    var _global;

    function result(args,fn){
        var argsArr = Array.prototype.slice.call(args);
        if(argsArr.length > 0){
            return argsArr.reduce(fn);
        } else {
            return 0;
        }
    }
    var taskList = {
        columnsInit:function(){
            return  [{
                field: 'id',
                title: '序号',
                width:'5%',
                align:'center',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },{
                field: 'taskCode',
                valign: 'middle',
                title: '任务编码'
            }, {
                field: 'iotTable',
                valign: 'middle',
                title: '存储表格'
            }, {
                field: 'iotCode',
                valign: 'middle',
                title: '设备编码',
                sortable : true
            },{
                field: 'iotName',
                title: '设备名称',
                valign: 'middle'
            },{
                field: 'iotTm',
                title: '采样时间',
                align:'center',
                valign: 'middle'
            },{
                field: 'iotScale',
                title: '精度',
                valign: 'middle'
            },{
                field: 'remarks',
                title: '备注',
                valign: 'middle'
            },{
                field: 'status',
                title: '状态',
                valign: 'middle',
                width: '150',
                align: 'center',
                formatter: function (value, row, index) {
                    if(value == '启用'){
                        return [
                            '<span class="sys-type-bg pro-status-green">启用</span>'
                        ];
                    }
                    return [
                        '<span class="sys-type-bg pro-status-red">停用</span>'
                    ];

                }
            },{
            	checkbox:true
            },{
                field: 'edit',
                title: '编辑',
                width: 100,
                align: 'center',
                formatter: function (value, row, index) {
                    return [
                        '<li><a href="j_task_data_add.html" title="编辑" class="opt-icon"><i class="glyphicon glyphicon-pencil"></i></a></li>',
                    ].join('');
                }

            }]
        },
        gridInit:function(columns){
            return $("#deviceTable").bootstrapTable({
                url:'',
                columns: columns,
                striped: 'true',
                classes: 'table table-hover qxttable',
                pagination: 'true',
                pageNumber: 1,
                pageSize: 10,
                pageList: [
                	 10, 20, 50, 100
                ],
                onPostBody:function () {
                    $(".opt-dropdown").hover(function(){
                        $(this).find(".opt-dropdown-menu").show();
                    },function(){
                        $(this).find(".opt-dropdown-menu").hide();
                    })
                }
            })

        },
        dataInit:function(){
            return  [{
                taskCode: 'ELE-JFPG-A1',
                iotTable: 'ELE-JFPG-A1',
                iotCode:'电表-尖10:00-11:00',
                iotName:'11:10:02',
                iotTm: '11:10:02',
                iotScale:'是是是',
                remarks: '对对对',
                status:'启用'
            },{
                taskCode: 'ELE-JFPG-A1',
                iotTable: 'ELE-JFPG-A1',
                iotCode:'电表-尖10:00-11:00',
                iotName:'11:10:02',
                iotTm: '11:10:02',
                iotScale:'是是是',
                remarks: '对对对',
                status:'停用'
            },{
                taskCode: 'ELE-JFPG-A1',
                iotTable: 'ELE-JFPG-A1',
                iotCode:'电表-尖10:00-11:00',
                iotName:'11:10:02',
                iotTm: '11:10:02',
                iotScale:'是是是',
                remarks: '对对对',
                status:'启用'
            },{
                taskCode: 'ELE-JFPG-A1',
                iotTable: 'ELE-JFPG-A1',
                iotCode:'电表-尖10:00-11:00',
                iotName:'11:10:02',
                iotTm: '11:10:02',
                iotScale:'是是是',
                remarks: '对对对',
                status:'启用'
            },{
                taskCode: 'ELE-JFPG-A1',
                iotTable: 'ELE-JFPG-A1',
                iotCode:'电表-尖10:00-11:00',
                iotName:'11:10:02',
                iotTm: '11:10:02',
                iotScale:'是是是',
                remarks: '对对对',
                status:'启用'
            },{
                taskCode: 'ELE-JFPG-A1',
                iotTable: 'ELE-JFPG-A1',
                iotCode:'电表-尖10:00-11:00',
                iotName:'11:10:02',
                iotTm: '11:10:02',
                iotScale:'是是是',
                remarks: '对对对',
                status:'启用'
            },{
                taskCode: 'ELE-JFPG-A1',
                iotTable: 'ELE-JFPG-A1',
                iotCode:'电表-尖10:00-11:00',
                iotName:'11:10:02',
                iotTm: '11:10:02',
                iotScale:'是是是',
                remarks: '对对对',
                status:'启用'
            },{
                taskCode: 'ELE-JFPG-A1',
                iotTable: 'ELE-JFPG-A1',
                iotCode:'电表-尖10:00-11:00',
                iotName:'11:10:02',
                iotTm: '11:10:02',
                iotScale:'是是是',
                remarks: '对对对',
                status:'启用'
            },{
                taskCode: 'ELE-JFPG-A1',
                iotTable: 'ELE-JFPG-A1',
                iotCode:'电表-尖10:00-11:00',
                iotName:'11:10:02',
                iotTm: '11:10:02',
                iotScale:'是是是',
                remarks: '对对对',
                status:'启用'
            },{
                taskCode: 'ELE-JFPG-A1',
                iotTable: 'ELE-JFPG-A1',
                iotCode:'电表-尖10:00-11:00',
                iotName:'11:10:02',
                iotTm: '11:10:02',
                iotScale:'是是是',
                remarks: '对对对',
                status:'启用'
            },{
                taskCode: 'ELE-JFPG-A1',
                iotTable: 'ELE-JFPG-A1',
                iotCode:'电表-尖10:00-11:00',
                iotName:'11:10:02',
                iotTm: '11:10:02',
                iotScale:'是是是',
                remarks: '对对对',
                status:'启用'
            }]
        }
    }

    // 将插件对象暴露给全局对象
    _global = (function(){ return this || (0, eval)('this'); }());
    if (typeof module !== "undefined" && module.exports) {
        module.exports = taskList;
    } else if (typeof define === "function" && define.amd) {
        define(function(){return taskList;});
    } else {
        !('plugin' in _global) && (_global.taskList = taskList);
    }
}());